package com.ysd.lis.service.sta.impl;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
 
public class AesDecryptionExample {
    public static void main(String[] args) {

        String text="VrIJQyTly1rRameXZZ7gXvzJ50kd4nY1zTPBT8/ipHRwKf5RxVAdxEuZrcippe11jQd1gdDgkF7zR+ldcTTvoK/pqqvp1hBZ+xjt3kNmUs6+NykbHfwb9OK0/8tx5JMKDRYxEdL/FMB8SObwy7xjtzL5k3pLPg3+WvydZqOL6w6A65jSQ8pQdo9UANLqkWyYfPGzNAhOuNBjSXm21Kd+mV0qQbC8nBFviLq6XpwRq1AFQQaFpat+GCIWfozclUSvZ4ae17jxFHAlBWC5UwmjniwTu5YJz+u/fr26ReDAR4khrTWO+Y1wk+rr2JOBq3ALsRD5QvAdxrYi8zHL4kP49g==";
        String privateK="MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCRj4FEvv6ei6QiSYpLv8IzSmIjEP/XWyPczQmVujzjQJRdIMc+o0vw5OyO9VL9lh+nlkUkZ2SlPEha/HmkHeW1pdC6hAJizDZS2xyzU3k8TxzWYy3/FbjtedoBtcvlZI9XyB1RkwSIX8w8/fPQZRJQ3wpVpA0/OSyffU8AhDtgex2aKaQ+qsjCUHONrIwWuF0tGR5H5DVBql3TCYt2AvXzUR6ixsX/adq8Tq4L4oqPPTX7tPMLBk+VAAAIhySP6Fbyz2KH6qrzC7/9PXVetMPom+y2858NCeooO8NJT152qv+yRRx1CQVPVts+70XLG9saLIlvrEaCzffvMJw3p8z/AgMBAAECggEADyoHmg1ZwlOi5E2MAks2ZJiFs8iEFr/wcwLLUlVmHXivXCpbh3uEoFKBEH2fSTrYDmH5zwqUciBfG1d9JqtUsIFXRu8Uvo0uxZ/9E/OIyE8nnnATrSTqsJbGrvHtDXdV9Zur7kEmMjzkrp/4RAgbieBKl9Rw6tq+etkXn2KnOuxAVwmBajCt26SQHhZqGGt+MafmKLcAKp10kNUZuQ0AMWrmID18OcfVVxr5pLEib2SMjLg266D08JUNiSykc3gunmoXQf4Et1qjM3kn8y2e1leaYEoCXR1+at5sgKwEOxH/tGK1Ox773YZ/iWeqLNIynWYSyhIVlzMa9i8Li9UuXQKBgQDB6ipWyXQl4ADF29YOOvY2VpS+MDCiKLSod1QOGKsZD5gkO80XOJ9TOTlFM178tZndp4xAq6Wr34MOE59Na/HY6n3KOTb6XXSHQKv6iWEif6hE+1TVqz0TdIfbM958wUTrHOGbY9QHRAGL3+RtNKmpbynQ9dodtfpEeWumiIhBEwKBgQDAKhaR/f5ClW4KPxnFMx6S21Ah5vOQoyA4saRokVdKkRRHIaRhxQud6vi8J4GeSnZfFitMJa04qHVsQhod9xNqrmWXoSAP/wiH3dUDD3XwMHLLQ4ujtpUoIOBrIG0njy6rrPoBpTsayL8Z3nG7ARtIMvsQgnyzhcQKZq1d0D3t5QKBgQCFGSw8a4P8ZzdAl3biR5gtjdoEfOE0vInbxCP+lPIDfo+n9x/7W1MIdZOYqvz8qc1VtaXv0aEiSoUSyWcjZf8XK0Rx5DmXOUQ9fadNjLQOUN73kicVjbabPvXtADorGSEr26QC209yOTxyfJe2WVpGwNVL5yPyFrEUBN9d7ALR3wKBgBdqiYmMu9j9QIV7HvbKveUDWIZpEDEFz71Y2EHtxAdQGnp4fQF0829w3JKA9eiGBlqb5vbGeI845+YjP+961iDf031govmQCEgWHgjbb3GvVa2zM2blrtNO/knPj72MUxGUaHqe2c7vu2m5k35IKjzoCXP/kpaFrFfgHywZXhKJAoGBAJRdZ/FDDbPG4GXq1Op22BoDEfWGi7TxeKQ8X07r0p/77huI/yhIGrJWTWhYzraXj0nk4iwXt2mbhLejcPRdDM4qeCxML6Amf4sBRbz3NXZ1QA8gyBt3bzOSFIoFVIqsFrNp6WUtTqbFtGysTkyo+ENc1cEJWu0Kcb57v7qUmOBM";
        try {
                // 假设 spec 是一个有效的私钥规范 (PKCS8EncodedKeySpec)
                // 解码 Base64 编码的私钥字符串
                byte[] decodedPrivateKey = Base64.getDecoder().decode(privateK);
                PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(decodedPrivateKey);
                KeyFactory kf = KeyFactory.getInstance("RSA");
                PrivateKey privateKey = kf.generatePrivate(spec);

                byte[] encryptedBytes = Base64.getDecoder().decode(text);
                // 使用私钥进行解密
                Cipher cipherDecrypt = Cipher.getInstance("RSA/ECB/PKCS1Padding");
                cipherDecrypt.init(Cipher.DECRYPT_MODE, privateKey); // 使用私钥解密
                byte[] decryptedBytes = cipherDecrypt.doFinal(encryptedBytes);
                String decryptedString = new String(decryptedBytes, "UTF-8");

                System.out.println("Decrypted Message: " + decryptedString);

            } catch (Exception e) {
                e.printStackTrace();
            }

    }
}